let str1 = 'abcd'
let str2 = 'abcde'

function solution(str1, str2) {
    let len1 = str1.length
    let len2 = str2.length
    let matrix = []
    for (let i = 0; i <= len1; i++) {
        matrix[i] = new Array()
        for (let j = 0; j <= len2; j++) {
            if (i == 0) {
                matrix[i][j] = j
            } else if (j === 0) {
                matrix[i][j] = i
            } else {
                let cost = 0
                if (str1[i - 1] != str2[j - 1]) {
                    cost = 1
                }
                const temp = matrix[i - 1][j - 1] + cost
                matrix[i][j] = Math.min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, temp)
            }
        }
    }
    return matrix[len1][len2]

}

console.log(solution(str1, str2))